/*************************************************************************************
 * managepoints.js
 * -----------
 * phpGMapTrips 
 * 
 * This php application allows you to easily record your travel destinations 
 * and display them with Google maps.
 * 
 * Author: Stephane Coste (lescoste@gmail.com)
 * Copyright: (c) 2006 Stephane Coste (http://lescoste.net/)
 * Release Version: 0.1
 * CVS Revision Version: $Revision: 1.2 $
 * Date Started: 2006/02/19
 * Last Modified: $Date: 2007/03/17 08:41:59 $
 *
 * CHANGES
 * -------
 * 2006/03/06 (0.3)
 *  -  First Release
 *
 *************************************************************************************
 *
 *     This file is part of phpGMapTrips.
 *
 *   phpGMapTrips is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   phpGMapTrips is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with phpGMapTrips; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ************************************************************************************/
var currentOverlay; // for debug

// draw trip points and line
function drawTrip(name, pointname) {
	var points = [];
	var tripdata = trips[name];
	var markers = tripdata.getElementsByTagName("marker");
	var tripGroups = tripdata.getElementsByTagName("groups");

	var menuelem = document.getElementById("menu_places");
	// erase all points
	var ulelem = document.getElementById("menupointsul");
	if (ulelem != undefined) {
		menuelem.removeChild(ulelem);
	}
	ulelem = document.createElement("ol");
	ulelem.setAttribute("id", "menupointsul");
	menuelem.appendChild(ulelem);

	tripPoints = new Array();
	for (var j = 0; j < markers.length; j++) {
		var i = j;
                var place = markers[i].getElementsByTagName("place");
		for (var k = 0; k < place.length; k++) {
			tripPoints[place[k].getAttribute("name")] = markers[i];
		
		// show point list
		separelem = document.createElement("li");
		separelem.innerHTML = " <a href='"+place[k].getAttribute("url")+"'><img src='"+place[k].getAttribute("photoimg")+"'/></a> <a id='a_"+ place[k].getAttribute("name") +"' href='javascript:void(0);' class='triplink' style='color:blue;' onclick='selectPointName(\"" + place[k].getAttribute("name") + "\");' title='"+lang_trips_show_link+" " + place[k].getAttribute("name") + "'>"+place[k].getAttribute("name") + "</a>";

		}


		ulelem.appendChild(separelem);
	}

	// display groups list
	var grelem = document.getElementById("tripgroupsElem");
	if (grelem != undefined) {
		menuelem.removeChild(grelem);
	}
	grelem = document.createElement("div");
	grelem.setAttribute("id", "tripgroupsElem");
	menuelem.appendChild(grelem);
	if (tripGroups.length >0) {
		addGroupInList(grelem, tripGroups[0].getAttribute("name"));
	}

	// select a point
	if (pointname == undefined || pointname=="") {
             var place = markers[0].getElementsByTagName("place");
             pointname = place[0].getAttribute("name");
        }
        var point = tripPoints[pointname];
	if (point == undefined) {
             var place = markers[0].getElementsByTagName("place");
		alert("'"+pointname+"' is not known, showing '"+place[0].getAttribute("name")+"' !");
             pointname = place[0].getAttribute("name");
        }
	selectPointName(pointname);
}

function selectPointNameMap(name, zoomin) {
// do nothing
}

// display current point details in editZone 
function showPointDetails(point) {
	if (point == undefined) {
		if (tripPoints == undefined) {
			return;
		} else {
			point = tripPoints[currentAPoint];
		} 
	}
	editMode =false;
	var pname = document.getElementById("p_name");
	pname.innerHTML = getPointDetails(point);

	toggleEditPoint();
}
function addGroupInList(ulelem, name) {
	// show point list
	separelem = document.createElement("span");
	separelem.innerHTML = name;
	ulelem.appendChild(separelem);
}